#include "VChannel.h"
#include "ui_VChannel.h"
#include <QDebug>
#include <QColorDialog>

VChannel::VChannel(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::VChannel)
{
    ui->setupUi(this);
    ui->pushButton_show->setProperty("iconText",true);
    ui->pushButton_show->setText(QChar(0xe66a));

    ui->widget_channel->installEventFilter(this);
//    ui->pushButton_show->installEventFilter(this);
    ui->widget_settings->setHidden(true);

//    ui->lineEdit_channel->installEventFilter(this);
}

VChannel::~VChannel()
{
    delete ui;
}

bool VChannel::eventFilter(QObject *watched, QEvent *event)
{
    if(watched == ui->widget_channel){
        if(event->type() == QEvent::MouseButtonPress
                || event->type() == QEvent::MouseButtonDblClick){
            ui->widget_settings->setHidden(!ui->widget_settings->isHidden());
            return true;
        }
    }

    return QWidget::eventFilter(watched,event);
}

void VChannel::on_pushButton_show_clicked(bool checked)
{
    //0xe697 不显示
    //0xe66a 显示
    ui->pushButton_show->setText(checked ? QChar(0xe697) : QChar(0xe66a));
}

void VChannel::on_pushButton_color_clicked()
{
    QColor color = QColorDialog::getColor();
    //判断是否选择了颜色
    if(color.isValid()){
        ui->pushButton_color->setColor(color);
        ui->label_channel_name->setStyleSheet(QString("color:%1;").arg(color.name()));
        ui->label_val->setStyleSheet(QString("color:%1;").arg(color.name()));
    }
}

void VChannel::on_lineEdit_channel_textChanged(const QString &arg1)
{
    ui->label_channel_name->setText(arg1);
}
